package com.todo.strategy.pipeline.application.handler.memo;

import com.todo.common.common.entity.response.BizResponse;
import com.todo.strategy.online.service.api.pipeline.request.InsertMemoTemplateRequest;
import com.todo.strategy.pipeline.application.entity.context.MemoOperateActionContext;
import com.todo.strategy.pipeline.application.remote.MemoPipelineRemoteService;
import com.todo.strategy.pipeline.common.enums.OperateActionEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/3/1 05:49
 * @description
 */
@Slf4j
@Component
public class MemoInsertHandler extends AbstractMemoOperateHandle {

    @Resource
    private MemoPipelineRemoteService memoPipelineRemoteService;

    @Override
    protected Boolean doActionHandle(MemoOperateActionContext context) {
        InsertMemoTemplateRequest request = new InsertMemoTemplateRequest();
        request.setBusinessId(context.getBusinessId());
        request.setOriginData(context.getOriginData());
        request.setEnableVersion(context.getEnableVersion());
        request.setCurrentVersion(context.getCurrentVersion());
        BizResponse<Boolean> bizResponse = memoPipelineRemoteService.insertMemoTemplate(request);
        if (bizResponse == null || !bizResponse.isSuccess() || !bizResponse.getData()){
            return false;
        }
        return true;
    }

    @Override
    protected Boolean match(MemoOperateActionContext context) {
        if (context.getOperateActionEnum().equals(getStrategyActionEnum())) {
            return true;
        }
        return false;
    }

    @Override
    protected OperateActionEnum getStrategyActionEnum() {
        return OperateActionEnum.INSERT;
    }
}
